package com.health.tablebean.webservice;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.NovaApplication;
import com.health.db.FDbManager;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.tablebean.CD_HYPERTENSIONFOLLOWUP;
import com.health.tablebean.PharmacyList;
import com.health.tools.GlobalConts;

import android.content.Context;
import android.text.TextUtils;

/**
 * 高血压
 */
public class Hypertensio {
	private static final String QXZ = "50";
	private static final String WZD = "50";
	private String avoirdupois;// 体重(kg)
	private String cardid;// 居民身份证/健康卡号
	private String compiance;// 遵医行为评价代码
	private String createorg;// 创建机构
	private String creater;// 创建人id
	private String createtime;// 创建时间
	private String curSymptom;// 症状
	private String dependence;// 服药依从性
	private String dieresult;// 死亡原因 失访死亡
	private String dietime;// 死亡时间 失访死亡
	private String drink;// 日饮酒量(两)
	private String effectsState;// 药物不良反应描述
	private String happentime;// 随访日期
	private String inputMan;// 随访人id
	private String mentality;// 心理调整
	private String nextVisitDate;// 下次随访时间
	private String otherPositive;// 体征其他
	private String otherSymptom;// 症状其他
	private String personalid;// 档案编号
	private List<PharmacyList> pharmacyList;// dosage 用量
											// drugName 药物名称
											// reg2 用药单位
											// usage 用法
	private String physique;// 体质指数（BMI)
	private String pressureH;// 收缩压
	private String pressureL;// 舒张压
	private String pulseRate;// 心率（次/分钟）
	private String qdqxz;// 缺项值
	private String qjbqk;// 迁往地点基本情况 失访迁出
	private String qjjjl;// 档案交接记录 失访迁出
	private String res0;// 是否吸烟
	private String res1;// 是否饮酒
	private String res4;// 失访原因
	private String res7;// 失访--具体失访原因（输入）
	private Rollout rollout;
	// private String hpc;// 转诊 原因
	// private String rollInRegion;// 机构及科别
	private String salt;// 摄盐量分级代码
	private String sideEffects;// 药物不良反应标志
	private String smoke;// 日吸烟量（支）
	private String subCheck;// 辅助检查结果描述
	private String targetAvoirdupois;// 目标体重（kg)
	private String targetDrink;// 目标日饮酒量(两）
	private String targetPhysique;// 目标体质指数
	private String targetSalt;// 目标摄盐量分级代码
	private String targetSmoke;// 目标日吸烟量（支）
	private String targetTraining;// 目标运动频率代码
	private String targetTrainingMin;// 目标每次锻炼时间(min)
	private String training;// 运动频率代码
	private String trainingMin;// 每次锻炼时间(min)
	private String visitType;// 随访评价结果代码(随访分类)
	private String visitWay;// 随访方式代码
	private String wzd;// 完整度
	private String fromType = "2";// 数据来源；空为公卫，‘1’为手提箱，‘2’为PAD
	private String updatetime;//修改时间

	public String getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(String updatetime) {
		this.updatetime = updatetime;
	}

	public Hypertensio() {
	}

	public String getAvoirdupois() {
		return avoirdupois;
	}

	public void setAvoirdupois(String avoirdupois) {
		this.avoirdupois = avoirdupois;
	}

	public String getCardid() {
		return cardid;
	}

	public void setCardid(String cardid) {
		this.cardid = cardid;
	}

	public String getCompiance() {
		return compiance;
	}

	public void setCompiance(String compiance) {
		this.compiance = compiance;
	}

	public String getCreateorg() {
		return createorg;
	}

	public void setCreateorg(String createorg) {
		this.createorg = createorg;
	}

	public String getCreater() {
		return creater;
	}

	public void setCreater(String creater) {
		this.creater = creater;
	}

	public String getCurSymptom() {
		return curSymptom;
	}

	public void setCurSymptom(String curSymptom) {
		this.curSymptom = curSymptom;
	}

	public String getDependence() {
		return dependence;
	}

	public void setDependence(String dependence) {
		this.dependence = dependence;
	}

	public String getDieresult() {
		return dieresult;
	}

	public void setDieresult(String dieresult) {
		this.dieresult = dieresult;
	}

	public String getDietime() {
		return dietime;
	}

	public void setDietime(String dietime) {
		this.dietime = dietime;
	}

	public String getDrink() {
		return drink;
	}

	public void setDrink(String drink) {
		this.drink = drink;
	}

	public String getEffectsState() {
		return effectsState;
	}

	public void setEffectsState(String effectsState) {
		this.effectsState = effectsState;
	}

	public String getInputMan() {
		return inputMan;
	}

	public void setInputMan(String inputMan) {
		this.inputMan = inputMan;
	}

	public String getMentality() {
		return mentality;
	}

	public void setMentality(String mentality) {
		this.mentality = mentality;
	}

	public String getOtherPositive() {
		return otherPositive;
	}

	public void setOtherPositive(String otherPositive) {
		this.otherPositive = otherPositive;
	}

	public String getOtherSymptom() {
		return otherSymptom;
	}

	public void setOtherSymptom(String otherSymptom) {
		this.otherSymptom = otherSymptom;
	}

	public String getPersonalid() {
		return personalid;
	}

	public void setPersonalid(String personalid) {
		this.personalid = personalid;
	}

	public List<PharmacyList> getPharmacyList() {
		return pharmacyList;
	}

	public void setPharmacyList(List<PharmacyList> pharmacyList) {
		this.pharmacyList = pharmacyList;
	}

	public String getPhysique() {
		return physique;
	}

	public void setPhysique(String physique) {
		this.physique = physique;
	}

	public String getPressureH() {
		return pressureH;
	}

	public void setPressureH(String pressureH) {
		this.pressureH = pressureH;
	}

	public String getPressureL() {
		return pressureL;
	}

	public void setPressureL(String pressureL) {
		this.pressureL = pressureL;
	}

	public String getPulseRate() {
		return pulseRate;
	}

	public void setPulseRate(String pulseRate) {
		this.pulseRate = pulseRate;
	}

	public String getQdqxz() {
		return qdqxz;
	}

	public void setQdqxz(String qdqxz) {
		this.qdqxz = qdqxz;
	}

	public String getQjbqk() {
		return qjbqk;
	}

	public void setQjbqk(String qjbqk) {
		this.qjbqk = qjbqk;
	}

	public String getQjjjl() {
		return qjjjl;
	}

	public void setQjjjl(String qjjjl) {
		this.qjjjl = qjjjl;
	}

	public String getRes0() {
		return res0;
	}

	public void setRes0(String res0) {
		this.res0 = res0;
	}

	public String getRes1() {
		return res1;
	}

	public void setRes1(String res1) {
		this.res1 = res1;
	}

	public String getRes4() {
		return res4;
	}

	public void setRes4(String res4) {
		this.res4 = res4;
	}

	public String getRes7() {
		return res7;
	}

	public void setRes7(String res7) {
		this.res7 = res7;
	}

	public Rollout getRollout() {
		return rollout;
	}

	public void setRollout(Rollout rollout) {
		this.rollout = rollout;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getSideEffects() {
		return sideEffects;
	}

	public void setSideEffects(String sideEffects) {
		this.sideEffects = sideEffects;
	}

	public String getSmoke() {
		return smoke;
	}

	public void setSmoke(String smoke) {
		this.smoke = smoke;
	}

	public String getTargetAvoirdupois() {
		return targetAvoirdupois;
	}

	public void setTargetAvoirdupois(String targetAvoirdupois) {
		this.targetAvoirdupois = targetAvoirdupois;
	}

	public String getTargetDrink() {
		return targetDrink;
	}

	public void setTargetDrink(String targetDrink) {
		this.targetDrink = targetDrink;
	}

	public String getTargetPhysique() {
		return targetPhysique;
	}

	public void setTargetPhysique(String targetPhysique) {
		this.targetPhysique = targetPhysique;
	}

	public String getTargetSmoke() {
		return targetSmoke;
	}

	public void setTargetSmoke(String targetSmoke) {
		this.targetSmoke = targetSmoke;
	}

	public String getTargetTrainingMin() {
		return targetTrainingMin;
	}

	public void setTargetTrainingMin(String targetTrainingMin) {
		this.targetTrainingMin = targetTrainingMin;
	}

	public String getTrainingMin() {
		return trainingMin;
	}

	public void setTrainingMin(String trainingMin) {
		this.trainingMin = trainingMin;
	}

	public String getSubCheck() {
		return subCheck;
	}

	public void setSubCheck(String subCheck) {
		this.subCheck = subCheck;
	}

	public String getTargetSalt() {
		return targetSalt;
	}

	public void setTargetSalt(String targetSalt) {
		this.targetSalt = targetSalt;
	}

	public String getTargetTraining() {
		return targetTraining;
	}

	public void setTargetTraining(String targetTraining) {
		this.targetTraining = targetTraining;
	}

	public String getTraining() {
		return training;
	}

	public void setTraining(String training) {
		this.training = training;
	}

	public String getVisitType() {
		return visitType;
	}

	public void setVisitType(String visitType) {
		this.visitType = visitType;
	}

	public String getVisitWay() {
		return visitWay;
	}

	public void setVisitWay(String visitWay) {
		this.visitWay = visitWay;
	}

	public String getWzd() {
		return wzd;
	}

	public void setWzd(String wzd) {
		this.wzd = wzd;
	}

	public String getFromType() {
		return fromType;
	}

	public void setFromType(String fromType) {
		this.fromType = fromType;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

	public String getHappentime() {
		return happentime;
	}

	public void setHappentime(String happentime) {
		this.happentime = happentime;
	}

	public String getNextVisitDate() {
		return nextVisitDate;
	}

	public void setNextVisitDate(String nextVisitDate) {
		this.nextVisitDate = nextVisitDate;
	}



	public static List<Hypertensio> convertData(Context context) {
		List<CD_HYPERTENSIONFOLLOWUP> datas = FDbManager.getInstance(context).findAllByWhere(
				CD_HYPERTENSIONFOLLOWUP.class, "IS_UPDATE='" + "Y' AND CREATER='" + NovaApplication.getJgrno() + "'");
//		List<CD_HYPERTENSIONFOLLOWUP> datas = FDbManager.getInstance(context)
//				.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, "IS_UPDATE='" + "Y'");
		List<Hypertensio> wbdatas = new ArrayList<Hypertensio>();
		Hypertensio wbdata;
		for (CD_HYPERTENSIONFOLLOWUP data : datas) {
			wbdata = new Hypertensio();
			wbdata.setAvoirdupois(data.getWEIGHT());// 体重(kg)
			wbdata.setCardid(data.getIDCARD());// 居民身份证/健康卡号
			wbdata.setCompiance(data.getOBEYDOCTORBEHAVIOR());// 遵医行为评价代码
			wbdata.setCreateorg(data.getCREATEORG());// 创建机构
			wbdata.setCreater(data.getCREATER());// 创建人id CREATED_BY
			wbdata.setCreatetime(GlobalConts.datetimeFormat.format(data.getCREATED_DATE()));// 创建时间
			wbdata.setCurSymptom(data.getSYMPTOM());// 症状
			wbdata.setDependence(data.getMEDICATIONCOMPLIANCE());// 服药依从性
			// wbdata.setDieresult (data.get());//死亡原因 失访死亡
			// wbdata.setDietime (data.get());//死亡时间 失访死亡
			wbdata.setDrink(data.getDAILYDRINKNUM());// 日饮酒量(两)
			wbdata.setEffectsState(data.getADR_EX());// 药物不良反应描述
			wbdata.setHappentime(
					data.getFOLLOWUPDATE() == null ? "" : GlobalConts.dateFormat.format(data.getFOLLOWUPDATE()));// 随访日期
			wbdata.setInputMan(data.getFOLLOWUPDOCTOR());// 随访人id
			wbdata.setMentality(data.getPSYCHOADJUSTMENT());// 心理调整
			wbdata.setNextVisitDate(data.getNEXTFOLLOWUPDATE() == null ? ""
					: GlobalConts.dateFormat.format(data.getNEXTFOLLOWUPDATE()));// 下次随访时间
			wbdata.setOtherPositive(data.getPHYSICALSYMPTOMOTHER());// 体征其他
			wbdata.setOtherSymptom(data.getSYMPTOMOTHER());// 症状其他
			wbdata.setPersonalid(data.getARCHIVEID());// 档案编号
			// wbdata.setPharmacyList(pharmacyList); //dosage 用量
			wbdata.setPhysique(data.getBMI());// 体质指数（BMI)
			wbdata.setPressureH(data.getHYPERTENSION());// 收缩压
			wbdata.setPressureL(data.getHYPOTENSION());// 舒张压
			wbdata.setPulseRate(data.getHEARTRATE());// 心率（次/分钟）
			// wbdata.setQjbqk(data.get());// 迁往地点基本情况 失访迁出
			// wbdata.setQjjjl(data.get());// 档案交接记录 失访迁出

			if (TextUtils.isEmpty(data.getDAILYSMOKENUM()) && TextUtils.isEmpty(data.getDAILYSMOKENUMTARGET())) {
				wbdata.setRes0("DM01-10_1");// 是否吸烟否
			} else {
				wbdata.setRes0("DM01-10_2");// 是否吸烟是
			}
			if (TextUtils.isEmpty(data.getDAILYDRINKNUM()) && TextUtils.isEmpty(data.getDAILYDRINKNUMTARGET())) {
				wbdata.setRes1("DM01-10_1");// 是否饮酒否
			} else {
				wbdata.setRes1("DM01-10_2");// 是否饮酒
			}
			// wbdata.setRes4 (data.get());// 失访原因
			// wbdata.setRes7 (data.get());// 失访--具体失访原因（输入）
			Rollout rollout = new Rollout();
			rollout.setHpc(data.getREFERRALREASON());
			rollout.setRollInRegion(data.getREFERRALORG());
			wbdata.setRollout(rollout);
			// wbdata.setHpc(data.getREFERRALREASON());// 转诊原因
			// wbdata.setRollInRegion(data.getREFERRALORG());// 机构及科别
			wbdata.setSalt(data.getEATSALTTYPE()); // 摄盐量分级代码
			wbdata.setSideEffects(data.getADR());// 药物不良反应标志
			wbdata.setSmoke(data.getDAILYSMOKENUM());// 日吸烟量（支）
			wbdata.setSubCheck(data.getASSISTANTEXAM());// 辅助检查结果描述
			wbdata.setTargetAvoirdupois(data.getWEIGHTTARGET());// 目标体重（kg)
			wbdata.setTargetDrink(data.getDAILYDRINKNUMTARGET());// 目标日饮酒量(两）
			wbdata.setTargetPhysique(data.getBMITARGET());// 目标体质指数
			wbdata.setTargetSalt(data.getEATSALTTARGET());// 目标摄盐量分级代码
			wbdata.setTargetSmoke(data.getDAILYSMOKENUMTARGET());// 目标日吸烟量（支）
			wbdata.setTargetTraining(data.getSPORTTIMESPERWEEKTARGET());// 目标运动频率代码
			wbdata.setTargetTrainingMin(data.getSPORTPERMINUTESTIMETARGET());// 目标每次锻炼时间(min)
			wbdata.setTraining(data.getSPORTTIMEPERWEEK());// 运动频率代码
			wbdata.setTrainingMin(data.getSPORTPERMINUTETIME());// 每次锻炼时间(min)
			wbdata.setVisitType(data.getFOLLOWUPTYPE());// 随访评价结果代码(随访分类)
			if (data.getFOLLOWUPWAY().contains("DM04-04")){
				wbdata.setVisitWay(data.getFOLLOWUPWAY().replace("DM04-04","DM04-15"));// 随访方式代码
			}else{
				wbdata.setVisitWay(data.getFOLLOWUPWAY());// 随访方式代码
			}
			wbdata.setFromType("2");
			wbdata.setUpdatetime(GlobalConts.datetimeFormat.format(data.getLAST_UPDATE_DATE()));

			FDbManager dbm = FDbManager.getInstance(context);
			List<CD_DRUGCONDITION> drs = dbm.findAllByWhere(CD_DRUGCONDITION.class,
					"IDCARD = '" + data.getIDCARD() + "'  AND TYPE = '1'");
			if (drs != null && !drs.isEmpty()) {
				// wbdata.setPharmacyList(pharmacyList
				List<PharmacyList> phs = new ArrayList<>();
				PharmacyList ph = null;
				for (CD_DRUGCONDITION dr : drs) {
					ph = new PharmacyList();
					ph.setDosage(dr.getEVERYTIMEMG());
					ph.setDrugName(dr.getNAME());
					if (TextUtils.isEmpty(dr.getRES1())) {	
						ph.setReg2("DM04-05_01");// 默认为mg
					}else{
						ph.setReg2(dr.getRES1());
					}
					ph.setUsage(dr.getDAILYTIME());
					phs.add(ph);
				}
				wbdata.setPharmacyList(phs);
			} else {
				wbdata.setPharmacyList(new ArrayList());
			}
			String[] arr = GlobalConts.assessIntegrity(wbdata.getAvoirdupois(), wbdata.getCompiance(),
					wbdata.getCurSymptom(), wbdata.getDependence(), wbdata.getHappentime(), wbdata.getInputMan(),
					wbdata.getMentality(), wbdata.getNextVisitDate(), wbdata.getOtherPositive(), wbdata.getPressureH(),
					wbdata.getPulseRate(), wbdata.getRes0(), wbdata.getRes1(),
					wbdata.getRollout().getHpc() + wbdata.getRollout().getRollInRegion(), wbdata.getSideEffects(),
					wbdata.getSubCheck(), wbdata.getTargetSalt(), wbdata.getTargetTraining(), wbdata.getVisitType(),
					wbdata.getVisitWay());
			wbdata.setWzd(arr[0]);// 完整度
			wbdata.setQdqxz(arr[1]);// 缺项值
			wbdatas.add(wbdata);
		}
		return wbdatas;
	}
}